package com.sise.wangzhan.controller;

import com.sise.wangzhan.client.BookService;
import com.sise.wangzhan.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname BookController
 * @Description TODO
 * @Date 2020/5/21 9:43
 * @Created by wangzhan
 */
@RestController
public class BookController {

    @Autowired
    BookService bookService;

    @RequestMapping(value = "/sale-book/{bookId}", method = RequestMethod.GET)
    public String saleBook(@PathVariable int bookId) {
        Book book = bookService.getBook(bookId);

        System.out.println("书id：" + book.getId() +"，书名：" + book.getName() + ",书作者：" + book.getAuthor());

        return "SALE SUCCESS";
    }

    /*@RequestMapping(value = "/errorTest2", method = RequestMethod.GET)
    public String errorTest() {
       String result = bookService.errorTest();
       return result;
    }*/


    @RequestMapping(value = "/errorTest", method = RequestMethod.GET)
    public String errorTest() throws Exception {
        Thread.sleep(3000);
        return "errorTest";
    }

}
